package com.zrentech.order.data.dbhelper.builder;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.database.Cursor;

import com.zrentech.order.data.busibean.OrderDetailBean;
import com.zrentech.order.data.dbhelper.DatabaseBuilder;

/**
 * 
 * 提供关于订单明细的创建和解析方面的功能
 * 
 * @author Leon
 */

public class OrderDetailDBuilder extends DatabaseBuilder<OrderDetailBean> {

	public static final String TRACK_ID = "id";
	public static final String TRACK_ORDERID = "orderID";
	public static final String TRACK_MENUID = "menuID";
	public static final String TRACK_NUM = "num";
	public static final String TRACK_REMARK = "remark";

	@Override
	public OrderDetailBean build(Cursor query) {
		int columnId = query.getColumnIndex(TRACK_ID);
		int columnOrderID = query.getColumnIndex(TRACK_ORDERID);
		int columnMenuid = query.getColumnIndex(TRACK_MENUID);
		int columnNum = query.getColumnIndex(TRACK_NUM);
		int columnRemark = query.getColumnIndex(TRACK_REMARK);

		OrderDetailBean detail = new OrderDetailBean();
		detail.setId(query.getInt(columnId));
		detail.setOrderID(query.getInt(columnOrderID));
		detail.setMenuID(query.getInt(columnMenuid));
		detail.setNum(query.getInt(columnNum));
		detail.setRemark(query.getString(columnRemark));
		return detail;
	}

	public List<OrderDetailBean> buildMore(Cursor query) {
		List<OrderDetailBean> orderDetails = new ArrayList<OrderDetailBean>();
		OrderDetailBean detail = null;
		if(query.moveToFirst()) {
			for(int i=0; i<query.getCount(); i++) {
				query.move(i);
				int columnId = query.getColumnIndex(TRACK_ID);
				int columnOrderID = query.getColumnIndex(TRACK_ORDERID);
				int columnMenuid = query.getColumnIndex(TRACK_MENUID);
				int columnNum = query.getColumnIndex(TRACK_NUM);
				int columnRemark = query.getColumnIndex(TRACK_REMARK);

				detail = new OrderDetailBean();
				detail.setId(query.getInt(columnId));
				detail.setOrderID(query.getInt(columnOrderID));
				detail.setMenuID(query.getInt(columnMenuid));
				detail.setNum(query.getInt(columnNum));
				detail.setRemark(query.getString(columnRemark));
				orderDetails.add(detail);
			}
		}
		return orderDetails;
	}
	
	@Override
	public ContentValues deconstruct(OrderDetailBean track) {
		ContentValues values = new ContentValues();
		values.put(TRACK_ID, track.getId());
		values.put(TRACK_ORDERID, track.getOrderID());
		values.put(TRACK_MENUID, track.getMenuID());
		values.put(TRACK_NUM, track.getNum());
		values.put(TRACK_REMARK, track.getRemark());
		return values;
	}

}
